/**
 * 能发送ajax请求的函数模块
 */
import axios from 'axios'
export default function ajax(url, data = {}, type = 'GET') {
  if (type === 'GET') {
    // 准备 url query 参数数据
    // let data = {usernmae: 'xiaohei', password: '123', tpye: 'dsf'}
    // username=xiaohei&password=123&type=dsf
    let parstr = ''
    Object.keys(data).forEach(key => {
      parstr += key + '=' + data[key] + '&'
    })
    if (parstr) {
      parstr = parstr.substring(0, parstr.length - 1)
    }
    url = url + '?' + parstr
    return axios.get(url)
  } else {  //POST
    return axios.post(url, data)
  }

}